#!/usr/bin/perl -T
# form.pl
use warnings;
# lack of use strict;

use CGI qw(:standard *table);
use Locale::Language;
use Locale::Country;

if (!param('name')) {
   print header, start_html(-bgcolor => 'white', -title => "ID card"),
   start_table({bgcolor => 'lightblue', cellspacing => 0, cellpadding => 5}
   ), start_form,
  
   Tr(td("Name" ),td({colspan => 3},textfield('name'))), "\n",
 

   Tr(td(["Language you understand",
   radio_group('lang', [English, French, Spanish])])), "\n", 
   Tr(td({colspan => 4, align => 'center'}, submit())), end_form, end_table;

} else {   #Process form and set cookie
   my @cookies;
   push(@cookies, 
   cookie(-name => 'name', -value => param('name'),
          -expires => '+3M', -path => '/cgi-bin'));
   push(@cookies, cookie (-name => 'lang', -value =>
                          language2code(param('lang')),
                          -expires => '+3M', -path => '/cgi-bin'));

   print header(-cookie => \@cookies),
   start_html(-bgcolor => 'white', -title => "ID card accepted"),
              "Application accepted \n";
}
print end_html;
